import collections

ntCoreUsage = collections.namedtuple('usage', 'name user nice system idle')


def get_core_stat_list():
    cpulist = []
    f = open("/proc/stat", "r")

    for line in f:
        line = line.replace('  ', ' ')
        vals = line.split(" ")
        if vals[0].startswith('cpu'):
            core = ntCoreUsage(vals[0], int(vals[1]), int(vals[2]), int(vals[3]), int(vals[4]))
            cpulist.append(core)

    f.close()
    return cpulist


def diff_core_stat_list(list1, list2):
    list3 = []
    for i in range(len(list1)):
        i1 = list1[i]
        i2 = list2[i]
        i3 = ntCoreUsage(i1[0], i1[1] - i2[1], i1[2] - i2[2], i1[3] - i2[3], i1[4] - i2[4])
        list3.append(i3)
    return list3
